﻿$(function () {
    var corpUserGuid = $("#hdnCorpUserGuid").val();
    var snapGuid = $("#hdnSnapGuid").val();
    var snapState = $("#hdnSnapState").val();
    if (snapGuid != null && snapGuid != "") {
        //修改操作，从历史记录中获取数据
        $.getJSON("../Handlers/EnterpriseCorpInfoHandler.ashx", { "action": "GetCompanyInfoBySnapGuid", "snapGuid": snapGuid, "rand": Math.random() }, function (data) {
            if (data) {
                var companyInfo = data.CompanyInfoKH;
                SetControlVal("CompanyinfoKH", companyInfo);
                var capitalBusinessInfo = data.CapitalBusinessKH;
                SetControlVal("CapitalBusinessKH", capitalBusinessInfo);
                var projectAchieveMentKH = data.ProjectAchieveMentKH;
                SetControlVal("ProjectAchieveMentKH", projectAchieveMentKH);
            }
        }
    );
    }
    else {
        //添加数据
        $.getJSON("../Handlers/EnterpriseCorpInfoHandler.ashx", { "action": "GetCompanyinfoBusinessInfoKH", "corpUserGuid": corpUserGuid, "snapGuid": snapGuid, "rand": Math.random() }, function (data) {
            if (data) {
                var companyInfo = data.CompanyInfoKH;
                SetControlVal("CompanyinfoKH", companyInfo);
                var capitalBusinessInfo = data.CapitalBusinessKH;
                SetControlVal("CapitalBusinessKH", capitalBusinessInfo);
                //                var projectAchieveMentKH = data.ProjectAchieveMentKH;
                //                SetControlVal("ProjectAchieveMentKH", projectAchieveMentKH);
            }
        }
    );
    }
    ////资金及经营情况 保存事件
    $("#btnCapitalSave").click(SaveCompanyAttchInfo);
    $("#btnProjectAchieveMentSave").click(SaveCompanyAttchInfo);
    InitControlState();
}
);




function SaveCompanyAttchInfo() {
    var _corpUserGuid = $("#hdnCorpUserGuid").val();
    var dataValid = CheckControlValid("btnCapitalSave");
    if (!dataValid) {
        return false;
    }
    var capitalInfo = GetData("btnCapitalSave");
    var pAchieveInfo = GetData("btnProjectAchieveMentSave");
    ////保存资金及经营情况
    $.post(
        "../Handlers/EnterpriseCorpInfoHandler.ashx",
         { "action": "CompanyAttchInfoKHEdit", "corpUserGuid": _corpUserGuid, "capitalInfo": capitalInfo, "pAchieveInfo": pAchieveInfo },
         function (data) {
             if (data) {
                 alert(data.Message);
             }
         }, "json"
        );
}

function InitControlState() {
    var snapState = $("#hdnSnapState").val();
    if (snapState == "0") {
        //资金及经营情况、工程业绩不可编辑
        $("input").attr("disabled", "disabled");
    }
}

//日期格式转化
function DateFormatConvert(date) {
    var dateStr = date;
    if (typeof date == "object") {
        dateStr = date.toLocaleString();
    } else if (typeof date == "string") {
        dateStr = date;
    }
    return dateStr.replace(/^([\d-]+)T([\d:]+).+$/, "$1 $2");
}
////修改企业开户行
function CompanyBankEdit() {
    if (!CheckData()) {
        return false;
    }
    var parmer = {};
    parmer.action = "BankEdit";
    parmer.corpGuid = $("#hdnCorpUserGuid").val();
    parmer.areaCode = $("#hdAreaCode").val();
    parmer.bankName = $("#txtBankName").val();
    parmer.bankAccNo = $("#txtBankAccNo").val();
    parmer.rand = Math.random();
    $.getJSON("../Handlers/KaoHeHandler.ashx", parmer, function (data) {

        OpenAlert(data.Message);
    });
}
////开户行验证
function CheckData() {
    if ($.trim($("#txtBankName").val()) == "") {
        alert("开户行名称不能为空！");
        return false;
    }
    if ($.trim($("#txtBankAccNo").val()) == "") {
        alert("开户行账号不能为空！");
        return false;
    }
    return true;
}

